package com.kpmg.datalake.common.exception;


import com.kpmg.datalake.common.enums.ResultCodeEnum;

/**
 * 自定义业务异常
 *
 * @author Alex.zhao [alex.zhao@kpmg.com]
 * @since Created on azhao6 on 2018-06-27 13:12:33
 */
public class BusinessException extends RuntimeException {

    private static final long serialVersionUID = 8810606578663475077L;

    private Integer code;

    private ResultCodeEnum resultCodeEnum;

    public BusinessException(ResultCodeEnum resultCodeEnum) {
        super(resultCodeEnum.getDisplay());
        this.resultCodeEnum = resultCodeEnum;
        this.code = resultCodeEnum.getCode();
    }

    public BusinessException(ResultCodeEnum resultCodeEnum, String msg) {
        super(msg);
        this.resultCodeEnum = resultCodeEnum;
        this.code = resultCodeEnum.getCode();
    }

    public BusinessException(ResultCodeEnum resultCodeEnum, Exception e) {
        super(e);
        this.resultCodeEnum = resultCodeEnum;
        this.code = resultCodeEnum.getCode();

    }

    public BusinessException(Integer code, String msg) {
        super(msg);
        this.resultCodeEnum = ResultCodeEnum.getEnumByCode(code);
        this.code = code;
    }

    public BusinessException(Integer code, Exception e) {
        super(e);
        this.resultCodeEnum = ResultCodeEnum.getEnumByCode(code);
        this.code = code;
    }

    public ResultCodeEnum getResultCodeEnum() {
        return resultCodeEnum;
    }

    public ResultCodeEnum getCode() {
        return ResultCodeEnum.getEnumByCode(code);
    }

    public void setCode(Integer code) {
        this.code = code;
    }
}
